package com.example.springbootswagger.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.util.UUID;

@Data
@ApiModel(description = "返回响应数据")
public class RestMessage implements Serializable {

    public static final String SUCCESS_CODE = "0000";
    public static final String SUCCESS_MESSAGE = "success";

    @ApiModelProperty(value = "是否成功")
    private boolean success = true;

    @ApiModelProperty(value = "返回数据")
    private Object data;

    @ApiModelProperty(value = "返回码")
    private String code;

    @ApiModelProperty(value = "返回信息")
    private String message;

    public RestMessage(Object obj) {
        setData(obj);
        setCode(SUCCESS_CODE);
        setMessage(SUCCESS_MESSAGE);
    }

    public RestMessage(String code, String message) {
        setCode(code);
        setMessage(message);
    }

    public static RestMessage success() {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        return new RestMessage(uuid);
    }

    public static RestMessage fail(String code, String message) {
        return new RestMessage(code, message);
    }
}
